# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>
# Contributor: Arturo Penen <apenen@gmail.com>

pkgname=istio
pkgver=1.16.1
pkgrel=1
pkgdesc='Istio configuration command line utility for service operators to debug and diagnose their Istio mesh.'
arch=('loong64' 'x86_64')
url='https://github.com/istio/istio'
license=('Apache')
makedepends=('go')
source=("$pkgname-$pkgver.tar.gz::https://github.com/istio/istio/archive/$pkgver.tar.gz")
sha512sums=('8e51088eaa9edb93c17f6e3c971799c1cd40acc907683364e2b8cd88fa819a8570df740bb4d2c49ff84824eba2045baacb87f29c78aa29aee697ebc0c4c77022')
b2sums=('8873619820cf0428ab11ebcff32b7069c9eccdea33b49c1ed7baa7d26f28ca371404616e4558859eac6784d98d851e6681e967faec139f0d42a46c760a07f00e')

build() {
  cd $pkgname-$pkgver
  export VERSION=$pkgver
  export TAG=$pkgver
  export BUILD_WITH_CONTAINER=0
  make build
}

package() {
  install -Dm 755 "${srcdir}/$pkgname-$pkgver/out/linux_amd64/istioctl" "${pkgdir}/usr/bin/istioctl"

  # Populate bash and zsh completions
  install -dm 755 "${pkgdir}/usr/share/bash-completion/completions"
  install -dm 755 "${pkgdir}/usr/share/zsh/site-functions"
  "${pkgdir}/usr/bin/istioctl" collateral --bash
  mv istioctl.bash "${pkgdir}/usr/share/bash-completion/completions/istioctl"
  "${pkgdir}/usr/bin/istioctl" collateral --zsh
  mv _istioctl  "${pkgdir}/usr/share/zsh/site-functions/_istioctl"
}
